package com.bdqn.servlet;

import com.bdqn.entity.Brand;
import com.bdqn.service.BrandService;
import com.bdqn.service.impl.BrandServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/addBrandServlet")
public class AddBrandServlet extends HttpServlet {
    private BrandService brandService = new BrandServiceImpl();
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("text/html;charset=UTF-8");
        //获取前端页面传过来的参数
        String brandName = req.getParameter("brandName");
        String companyName = req.getParameter("companyName");
        int ordered = Integer.parseInt(req.getParameter("ordered"));
        String description = req.getParameter("description");
        int status = Integer.parseInt(req.getParameter("status"));
        //存放进实体类中
        Brand brand = new Brand(brandName,companyName,ordered,description,status);
        //调用方法进行添加
        int add = brandService.add(brand);
        if (add ==1){
            resp.getWriter().write("添加成功");
        }else {
            resp.getWriter().write("添加失败");
        }
    }
}
